﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;

namespace YArchitech.Temp
{
	public partial class DuctAttachInfoForm : System.Windows.Forms.Form
	{
		public DuctAttachInfoForm()
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
			base.CenterToParent();
			this.AttachObjValue.ValueRange = new MostValue(0.0, 1000.0);
		}

		public DuctAttachInfoForm(HYDuctStraight duct, bool terminalValueReadonly = true) : this()
		{
			this.m_Duct = duct;
			this.m_TerminalValueReadonly = terminalValueReadonly;
			if (this.m_Duct != null && this.m_Duct.AttachObjects != null)
			{
				foreach (HYPipeline.AttachObject ao in this.m_Duct.AttachObjects)
				{
					DataGridViewRow dataGridViewRow = this.CreateRow(ao);
					this.hyGridView1.Rows.Add(dataGridViewRow);
				}
			}
		}

		private DataGridViewRow CreateRow(HYPipeline.AttachObject ao)
		{
			DataGridViewRow dataGridViewRow = new DataGridViewRow();
			dataGridViewRow.CreateCells(this.hyGridView1);
			dataGridViewRow.Tag = ao;
			dataGridViewRow.Cells[0].Value = ao.ShowName;
			if (ao.Object is HYFitting)
			{
				dataGridViewRow.Cells[1].SetValue(ao.Value, 3);
			}
			else if (ao.Object is HYAccessory)
			{
				dataGridViewRow.Cells[2].SetValue(ao.Value, 3);
			}
			else if (ao.Object is HYTerminal)
			{
				dataGridViewRow.Cells[2].SetValue(ao.Value, 3);
			}
			return dataGridViewRow;
		}

		private void hyGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			this.hyInplaceTextBox1.OnHide();
			int rowIndex = e.RowIndex;
			int columnIndex = e.ColumnIndex;
			if (1 != columnIndex || rowIndex < 0)
			{
				return;
			}
			DataGridViewRow dataGridViewRow = this.hyGridView1.Rows[rowIndex];
			if (!(dataGridViewRow.Tag is HYPipeline.AttachObject))
			{
				return;
			}
			DataGridViewCell cell = dataGridViewRow.Cells[1];
			this.hyInplaceTextBox1.MoveToCell(cell);
		}

		private void hyGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
		{
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			if (this.m_Duct == null)
			{
				base.DialogResult = DialogResult.Cancel;
				return;
			}
			foreach (object obj in ((IEnumerable)this.hyGridView1.Rows))
			{
				DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
				HYPipeline.AttachObject attachObject = dataGridViewRow.Tag as HYPipeline.AttachObject;
				attachObject.Value = dataGridViewRow.Cells[1].GetDoubleValue();
				attachObject.Save();
			}
			double num;
			double num2;
			this.m_Duct.GetAttachObjectInfo(out num, out num2);
			base.DialogResult = DialogResult.OK;
		}

		private HYDuctStraight m_Duct;

		private bool m_TerminalValueReadonly;
	}
}
